package cn.cpf.cfets;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * <b>Description : </b>
 * <p>
 * <b>created in </b> 2021/2/1
 *
 * @author CPF
 * @since 1.0
 **/
@Slf4j
public class ImixTable {

    @Setter @Getter
    private String docName;
    @Setter @Getter
    private String tableName;
    @Setter @Getter
    private String tableIdx;
    @Setter @Getter
    private String tableComment;

    @Getter
    private final List<FieldRow> standardHeader = new ArrayList<>(10);
    @Getter
    private final List<FieldRow> messageBody = new ArrayList<>();
    @Getter
    private final List<FieldRow> standardTrailer = new ArrayList<>(2);

    public void addMessageBodyRow(FieldRow fieldRow) {
        this.messageBody.add(fieldRow);
    }

    public void addStandardTrailerRow(FieldRow fieldRow) {
        this.standardTrailer.add(fieldRow);
    }

    public void addStandardHeaderRow(FieldRow fieldRow) {
        this.standardHeader.add(fieldRow);
    }

    public void appendHandleComment(String string) {
        if (standardHeader.isEmpty()) {
            log.warn("standardHeader 为空 === {}", string);
            return;
        }
        final FieldRow fieldRow = standardHeader.get(standardHeader.size() - 1);
        fieldRow.setComment(fieldRow.getComment() + string);
    }

    public void appendBodyComment(String string) {
        if (messageBody.isEmpty()) {
            log.warn("messageBody 为空 === {}", string);
            return;
        }
        final FieldRow fieldRow = messageBody.get(messageBody.size() - 1);
        fieldRow.setComment(fieldRow.getComment() + string);
    }


}
